home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Atari Mega Archive 1
/
Atari Mega Archive - Volume 1.iso
/
mint
/
shells
/
tcsh602.zoo
/
tcsh602
/
csh.1
< prev
next >
Wrap
Text File
|
1993-02-23
|
72KB
|
1,451 lines
csh(1)
Name
csh - C shell Command Interpreter
Syntax
csh [-cefinstvVxX] [_✓a_✓r_✓g...]
Description
The _✓c_✓s_✓h command is a command language interpreter that consists of a
history mechanism, job control facilities, and a C-like syntax. While
this command has a set of _✓b_✓u_✓i_✓l_✓t-_✓i_✓n functions that it performs directly,
the command line interpreter also reads and translates commands that
invokes other programs. Additionally, you can create shell scripts
which the _✓c_✓s_✓h command can interpret. Shell scripts are files which con-
tain executable instructions.
The percent sign (%) represents the system prompt. It indicates that
you can begin entering commands to the system. Each command line that
you type is read and broken into words. This sequence of words is placed
on a command history list and then parsed. When the entire command line
has executed, the percent sign reappears and you can enter another com-
mand. See the History Substitution and Jobs sections for more informa-
tion.
To use the _✓c_✓s_✓h command's full job control facilities, you must invoke
the tty driver described in _✓t_✓t_✓y(4). This driver allows generation of
interrupt characters from the keyboard which stop execution of a job.
For details on setting options in the tty driver, see _✓s_✓t_✓t_✓y(1).
Note that your environment setup is controlled by commands in the home
directory of your .cshrc file. The _✓c_✓s_✓h command executes these commands
when you enter the system. Additionally, if this is a login shell, the
Shell also executes the commands in your .login file. These files usu-
ally contain your options for the tty driver and _✓t_✓s_✓e_✓t(1), (terminal set-
tings). When a login shell session ends, commands are executed from the
.logout file in your home directory.
Lexical Structure
The shell splits input lines into words at blanks and tabs with the fol-
lowing exceptions:
o✓+ ampersand (&)
o✓+ bar ( | )
o✓+ semicolon ( ; )
o✓+ Left (<) and right (>) angle brackets
o✓+ Left (() and right ()) parenthesis
The previous metacharacters form separate words. If doubled as follows,
these metacharacters form single words:
o✓+ Doubled ampersand (&&)
o✓+ Double bars (||)
o✓+ Double left (<<) and right (>>) brackets
o✓+ Backslash (\)
o✓+ Single (` `) and double (" ") quotation marks.
Metacharacters can be a part of other words. Additionally, if you do
not want a metacharacter to be interpreted as such by the system, you
can precede it with a backslash e (\e). A new line that is preceded by
a is equivalent to a blank.
Strings enclosed in single quotes (` `) or strings enclosed in double
quotes (" ") form parts of a word. Metacharacters in these strings,
including blanks and tabs, do not form separate words. This is
described in more detail later. Within single quotes or double quotes,
a new line preceded by a backslash (\) gives a true new line character.
When the shell's input is not a terminal, the pound sign (#) introduces
a comment which continues to the end of the input line. It is prevented
this special meaning when preceded by a backslash (\) and single or dou-
ble quotation marks.
Commands
A command is a word or sequence of words that directs the system to per-
form a certain function. You can separate commands with a bar ( | )
which forms a pipeline. The output that results from each command in
the pipeline is connected to the input of the next. For example, in the
following pipeline, a file is copied and the output is piped to standard
output (the screen):
% cp /example/dir/test . | more
You can form and execute several pipelines by separating each pipeline
with a semicolon (;). You can also force a command to complete execu-
tion in the background by typing an ampersand (&) at the end of the com-
mand line.
You can form a simple command (which may be a component of a pipeline
and so on) by placing any of the above in parenthesis (()). As in the C
language, you can also separate pipelines with a double bar (||) or dou-
ble ampersands (&&). The double bar tells the command interpreter to
execute the second command only if the first command fails. The double
ampersands tells the command interpreter to execute the second command
if the first command is successful.
Jobs
The Shell associates each command or pipeline with a _✓j_✓o_✓b index. By typ-
ing jobs at the system prompt, a table of the current jobs is printed on
your screen. Each job listed has a small integer number associated with
it. For example, if you force a job into the background using an amper-
sand (&), the shell displays the job number and process id of that job
as follows:
[1] 1234
In the previous example, the job number is 1 indicating that this is a
background job and the process id is 1234.
If you are running a job in the foreground, you can suspend execution of
that job by typing a CTRL/Z. The Shell then indicates that the job has
been stopped and the system prompt reappears. If you type jobs at the
prompt, the display indicates that a job has been stopped. You can
either enter another command at the prompt or you can manipulate the
state of the job you suspended as follows:
o✓+ Place the job in background by using the bg command.
o✓+ Continue to execute the job by placing it in the foreground using
the fg command.
A CTRL/Z takes effect immediately and is like an interrupt. For exam-
ple, pending output and unread output are discarded when the CTRL/Z is
issued. You can also type a CTRL/Y which does not generate a stop sig-
nal until a program attempts to perform a _✓r_✓e_✓a_✓d(2) operation.
If a job that is being run in the background attempts to read from the
terminal, it will stop. Background jobs can produce output. You can
prevent background jobs from producing output by issuing the following
command:
stty tostop
There are several ways to refer to jobs in the shell. For example, to
bring job number 1 into the foreground, type %1 or fg %1. Similarly, %1
& returns job 1 to the background. If a job does not have an ambiguous
prefix, you can restart a job by it's prefix. For example, %ex would
restart a suspended _✓e_✓x job, if it is the only suspended _✓e_✓x job. You use
also use %?_✓s_✓t_✓r_✓i_✓n_✓g which specifies a job whose command line contains
_✓s_✓t_✓r_✓i_✓n_✓g. Again, _✓s_✓t_✓r_✓i_✓n_✓g cannot be an ambiguous name.
The Shell tracks the current and previous jobs. For example, in output
displays of jobs, the current job is marked with a plus sign (+) and the
previous job is marked with a minus sign (-). Hence, you can type %+
for the current job and %- for the previous job. You can also specify
%% which specifies the current job.
Status Reporting
The Shell performs status reporting when the process state changes. For
example, if a job becomes blocked and further processing is not possi-
ble, the Shell informs you just before it prints a prompt. If, however,
you set the Shell variable _✓n_✓o_✓t_✓i_✓f_✓y, the Shell provides you with immediate
status of background jobs. As opposed to notifying you of all changes
in background jobs, the Shell command _✓n_✓o_✓t_✓i_✓f_✓y can mark a single process
so that only its status change is reported. To mark a single file, type
notify after starting a background job. By default, only the current
process is marked.
If you try to exit from the Shell while jobs are stopped, the following
warning appears:
You have stopped jobs.
You can use the jobs command to view the stopped jobs. If you immedi-
ately try to exit again, the Shell does not provide a second warning and
suspended jobs are terminated.
Substitutions
The various transformations the shell performs on the input is now
described in the order in which they occur.
History Substitutions
History substitutions allow you to use words from previously typed com-
mands as portions of new commands. This enables you to repeat commands,
arguments, or fix spelling mistakes from the previous command.
An exclamation point (!) marks the beginning of a history substitution.
It can appear anywhere in the input stream (including the beginning) as
long as it is not nested. An input line that contains history substitu-
tion is echoed to the screen before it is executed.
The exclamation point (!) may be preceded by a backslash (\) if you want
to escape its special meaning. If an exclamation point is followed by a
blank, tab, new line, equal sign (=), or left parenthesis ((), it is
passed unchanged.
Any command line that is typed at the terminal is saved on the history
list. You can increase or decrease the size of your history list using
the _✓h_✓i_✓s_✓t_✓o_✓r_✓y variable; the previous command is always retained regardless
of its value. Commands are numbered sequentially from 1. To display the
history on your terminal, type history at the prompt as follows:
% history
This command lists the commands that were previously typed. For exam-
ple:
1 write michael
2 ex write.c
3 cat oldwrite.c
4 diff*write.c
The commands are shown with their event numbers. Although it is not
usually necessary to use event numbers, you can reinvoke any command by
combining the exclamation point (!) with any event number. For example,
if you are referencing the previous history list, !4 reinvokes the com-
mand line diff*write.c. You can also reinvoke a command without the
event number as long as it is not ambiguous. For example, !c invokes
event 3 or !wri invokes event 1. The line !?mic? also refers to event
1. If you type !!, the last command entered in reinvoked.
To select words from an event, follow the event specification with a
colon (:) and a designator for the desired words. The words of a input
line are numbered from 0, the first (usually command) word being 0, the
second word (first argument) being 1, and so forth. The basic word
designators are:
0 first (command) word
_✓n _✓n'th argument
! first argument, that is `1'
$ last argument
% word matched by (immediately preceding) ?_✓s? search
_✓x-_✓y range of words
-_✓y abbreviates `0-_✓y'
* abbreviates `!-$', or nothing if only 1 word in event
_✓x* abbreviates `_✓x-$'
_✓x- like `_✓x*' but omitting word `$'
The colon (:) separating the event specification from the word designa-
tor can be omitted if the argument selector begins with a `!', `$', `*'
`-' or `%'. After the optional word designator can be placed a sequence
of modifiers, each preceded by a colon (:). The following modifiers are
defined:
h Remove a trailing pathname component, leaving the head.
r Remove a trailing `.xxx' component, leaving the root name.
e Remove all but the extension `.xxx' part.
s/_✓l/_✓r/ Substitute _✓l for _✓r
t Remove all leading pathname components, leaving the tail.
& Repeat the previous substitution.
g Apply the change globally, prefixing the above, for example, `g&'.
p Print the new command but do not execute it.
q Quote the substituted words, preventing further substitutions.
x Like q, but break into words at blanks, tabs and new lines.
Unless preceded by a `g' the modification is applied only to the first
modifiable word. With substitutions, it is an error for no word to be
applicable.
The left hand side of substitutions are not regular expressions in the
sense of the editors, but rather strings. Any character may be used as
the delimiter in place of `/'; a `\' quotes the delimiter into the _✓l and
_✓r strings. The character `&' in the right hand side is replaced by the
text from the left. A `\' quotes `&' also. A null _✓l uses the previous
string either from a _✓l or from a contextual scan string _✓s in `!?_✓s?'.
The trailing delimiter in the substitution may be omitted if a new line
follows immediately as may the trailing `?' in a contextual scan.
A special abbreviation of a history reference occurs when the first
non-blank character of an input line is a circumflex (^). This is
equivalent to `!!:s/' providing a convenient shorthand for substitutions
on the text of the previous line. Thus `^lb^lib^' fixes the spelling of
lb in the previous command. Finally, a history substitution may be sur-
rounded with `{' and `}' if necessary to insulate it from the characters
which follow. Thus, after `ls -ld ~paul' we might do `!{l}a' to do `ls
-ld ~paula', while `!la' would look for a command starting `la'.
Quotations with ' and "
The quotation of strings by `'' and `"' can be used to prevent all or
some of the remaining substitutions. Strings enclosed in `'' are
prevented any further interpretation. Strings enclosed in `"' may be
expanded as described below.
In both cases the resulting text becomes (all or part of) a single word;
only in one special case (see _✓C_✓o_✓m_✓m_✓a_✓n_✓d _✓S_✓u_✓b_✓s_✓t_✓i_✓t_✓u_✓t_✓i_✓o_✓n below) does a `"'
quoted string yield parts of more than one word; `'' quoted strings
never do.
Alias Substitution
The shell maintains a list of aliases that can be established,
displayed, and modified by the _✓a_✓l_✓i_✓a_✓s and _✓u_✓n_✓a_✓l_✓i_✓a_✓s commands.
After the shell scans a command line, it parses the line into distinct
commands. Then, the shell checks the first word of each command, in
left-to-right order, to determine if the command line contains an alias.
When the shell finds an alias, it substitutes the definition of the
alias for the alias in the command line. The shell reads the definition
of the alias using the history mechanism and treats the definition as if
it was the previous input line. If the alias definition makes no refer-
ence to the history list, the shell leaves the command's argument
unchanged.
For example, the following command creates an alias called ``ls:''
% alias ls 'ls -l'
After you issue this _✓a_✓l_✓i_✓a_✓s command, you receive information about files
such as their mode, number of links, owner, and so on when you use the
ls alias. For example, the following shows the output from the ls alias
created in the preceeding example:
% ls /usr/smith/text_file
-rw-r--r-- 1 smith 21 Mar 12 11:53 text_file
You can also create aliases that allow you to supply arguments on the
command line and arguments in the alias definition, as shown in the fol-
lowing example:
% alias lookup 'grep \!^ /etc/passwd'
You must specify ``\'' before the ! to prevent the substitution from
occurring in the _✓a_✓l_✓i_✓a_✓s command. The following shows the output from the
lookup alias:
% lookup smith
smith:2vruqPosbG/bE:1321:10::/usr/smith:/bin/csh
The lookup alias finds and displays user Smith's entry in the
/_✓e_✓t_✓c/_✓p_✓a_✓s_✓s_✓w_✓d file.
You can specify an alias within an alias definition. After the shell
finds an alias and substitutes its definition, it searches again for
aliases. The shell flags definitions that begin with the same word as
the alias to prevent infinite loops. Other loops are detected and cause
an error.
You can use parser metasyntax in an _✓a_✓l_✓i_✓a_✓s command. For example, the fol-
lowing is a valid command that creates the print alias:
% alias print 'pr \!* | lpr'
The print alias pipes output from the _✓p_✓r command to the _✓l_✓p_✓r command.
Variable Substitution
The shell maintains a set of variables, each of which has as value a
list of zero or more words. Some of these variables are set by the
shell or referred to by it. For instance, the _✓a_✓r_✓g_✓v variable is an image
of the shell's argument list, and words of this variable's value are
referred to in special ways.
The values of variables may be displayed and changed by using the _✓s_✓e_✓t
and _✓u_✓n_✓s_✓e_✓t commands. Of the variables referred to by the shell a number
are toggles; the shell does not care what their value is, only whether
they are set or not. For instance, the _✓v_✓e_✓r_✓b_✓o_✓s_✓e variable is a toggle
which causes command input to be echoed. The setting of this variable
results from the -v command line option.
Other operations treat variables numerically. The `@' command permits
numeric calculations to be performed and the result assigned to a vari-
able. Variable values are, however, always represented as (zero or
more) strings. For the purposes of numeric operations, the null string
is considered to be zero, and the second and subsequent words of multi-
word values are ignored.
After the input line is aliased and parsed, and before each command is
executed, variable substitution is performed keyed by `$' characters.
This expansion can be prevented by preceding the `$' with a `\' except
within `"'s where it always occurs, and within `''s where it never
occurs. Strings quoted by ``' are interpreted later (see _✓C_✓o_✓m_✓m_✓a_✓n_✓d _✓s_✓u_✓b_✓-
_✓s_✓t_✓i_✓t_✓u_✓t_✓i_✓o_✓n below) so `$' substitution does not occur there until later,
if at all. A `$' is passed unchanged if followed by a blank, tab, or
end-of-line.
Input/output redirections are recognized before variable expansion, and
are variable expanded separately. Otherwise, the command name and
entire argument list are expanded together. It is thus possible for the
first (command) word to this point to generate more than one word, the
first of which becomes the command name, and the rest of which become
arguments.
Unless enclosed in `"' or given the `:q' modifier the results of vari-
able substitution may eventually be command and file name substituted.
Within `"' a variable whose value consists of multiple words expands to
a (portion of) a single word, with the words of the variables value
separated by blanks. When the `:q' modifier is applied to a substitu-
tion the variable will expand to multiple words with each word separated
by a blank and quoted to prevent later command or file name substitu-
tion.
The following metasequences are provided for introducing variable values
into the shell input. Except as noted, it is an error to reference a
variable which is not set.
$name
${name}
Are replaced by the words of the value of variable _✓n_✓a_✓m_✓e, each
separated by a blank. Braces insulate _✓n_✓a_✓m_✓e from following charac-
ters which would otherwise be part of it. Shell variables have
names consisting of up to 20 letters and digits starting with a
letter. The underscore character is considered a letter.
If _✓n_✓a_✓m_✓e is not a shell variable, but is set in the environment,
then that value is returned (but : modifiers and the other forms
given below are not available in this case).
$name[selector]
${name[selector]}
May be used to select only some of the words from the value of
_✓n_✓a_✓m_✓e. The selector is subjected to `$' substitution and may consist
of a single number or two numbers separated by a `-'. The first
word of a variables value is numbered `1'. If the first number of
a range is omitted it defaults to `1'. If the last member of a
range is omitted it defaults to `$#name'. The selector `*' selects
all words. It is not an error for a range to be empty if the
second argument is omitted or in range.
$#name
${#name}
Gives the number of words in the variable. This is useful for
later use in a `[selector]'.
$0
Substitutes the name of the file from which command input is being
read. An error occurs if the name is not known.
$number
${number}
Equivalent to `$argv[number]'.
$*
Equivalent to `$argv[*]'.
The modifiers `:h', `:t', `:r', `:q' and `:x' may be applied to the sub-
stitutions above as may `:gh', `:gt' and `:gr'. If braces `{' '}'
appear in the command form then the modifiers must appear within the
braces.
_✓N_✓o_✓t_✓e
The current implementation allows only one colon (:) modifier
on each `$' expansion."
The following substitutions may not be modified with colon (:) modif-
iers.
$?name
${?name}
Substitutes the string `1' if name is set, `0' if it is not.
$?0
Substitutes `1' if the current input file name is known, `0' if it
is not.
$$
Substitute the (decimal) process number of the (parent) shell.
$<
Substitutes a line from the standard input, with no further
interpretation thereafter. It can be used to read from the key-
board in a shell script.
Command And File Name Substitution
The remaining substitutions, command and file name substitution, are
applied selectively to the arguments of built-in commands. This means
that portions of expressions which are not evaluated are not subjected
to these expansions. For commands which are not internal to the shell,
the command name is substituted separately from the argument list. This
occurs very late, after input-output redirection is performed, and in a
child of the main shell.
Command Substitution
Command substitution is indicated by a command enclosed in ``'. The
output from such a command is normally broken into separate words at
blanks, tabs and new lines, with null words being discarded, this text
then replacing the original string. Within `"'s, only new lines force
new words; blanks and tabs are preserved.
In any case, the single final new line does not force a new word. Note
that it is thus possible for a command substitution to yield only part
of a word, even if the command outputs a complete line.
File Name Substitution
If a word contains any of the characters `*', `?', `[' or `{' or begins
with the character `~', then that word is a candidate for file name sub-
stitution, also known as `globbing'. This word is then regarded as a
pattern, and replaced with an alphabetically sorted list of file names
which match the pattern. In a list of words specifying file name sub-
stitution it is an error for no pattern to match an existing file name,
but it is not required for each pattern to match. Only the metacharac-
ters `*', `?' and `[' imply pattern matching, the characters `~' and `{'
being more akin to abbreviations.
In matching file names, the character `.' at the beginning of a file
name or immediately following a `/', as well as the character `/' must
be matched explicitly. The character `*' matches any string of charac-
ters, including the null string. The character `?' matches any single
character. The sequence `[...]' matches any one of the characters
enclosed. Within `[...]', a pair of characters separated by `-' matches
any character lexically between the two.
The character `~' at the beginning of a file name is used to refer to
home directories. Standing alone, that is `~', it expands to the invok-
ers home directory as reflected in the value of the variable _✓h_✓o_✓m_✓e. When
followed by a name consisting of letters, digits and `-' characters the
shell searches for a user with that name and substitutes their home
directory; thus `~ken' might expand to `/usr/ken' and `~ken/chmach' to
`/usr/ken/chmach'. If the character `~' is followed by a character
other than a letter or `/' or appears not at the beginning of a word, it
is left undisturbed.
The metanotation `a{b,c,d}e' is a shorthand for `abe ace ade'. Left to
right order is preserved, with results of matches being sorted
separately at a low level to preserve this order. This construct may be
nested. Thus `~source/s1/{oldls,ls}.c' expands to
`/usr/source/s1/oldls.c /usr/source/s1/ls.c' whether or not these files
exist without any chance of error if the home directory for `source' is
`/usr/source'. Similarly `../{memo,*box}' might expand to `../memo
../box ../mbox'. (Note that `memo' was not sorted with the results of
matching `*box'.) As a special case `{', `}' and `{}' are passed undis-
turbed.
Input/output
The standard input and standard output of a command may be redirected
with the following syntax:
< name
Open file _✓n_✓a_✓m_✓e (which is first variable, command and file name
expanded) as the standard input.
<< word
Read the shell input up to a line which is identical to _✓w_✓o_✓r_✓d. _✓W_✓o_✓r_✓d
is not subjected to variable, file name or command substitution,
and each input line is compared to _✓w_✓o_✓r_✓d before any substitutions
are done on this input line. Unless a quoting `\', `"', `'' or ``'
appears in _✓w_✓o_✓r_✓d variable and command substitution is performed on
the intervening lines, allowing `\' to quote `$', `\' and ``'.
Commands which are substituted have all blanks, tabs, and new lines
preserved, except for the final new line which is dropped. The
resultant text is placed in an anonymous temporary file which is
given to the command as standard input.
> name
>! name
>& name
>&! name
The file _✓n_✓a_✓m_✓e is used as standard output. If the file does not
exist then it is created; if the file exists, it is truncated, its
previous contents being lost.
If the variable _✓n_✓o_✓c_✓l_✓o_✓b_✓b_✓e_✓r is set, then the file must not exist or
be a character special file (for example, a terminal or
`/dev/null') or an error results. This helps prevent accidental
destruction of files. In this case the `!' forms can be used and
suppress this check.
The forms involving `&' route the diagnostic output into the speci-
fied file as well as the standard output. _✓N_✓a_✓m_✓e is expanded in the
same way as `<' input file names are.
>> name
>>& name
>>! name
>>&! name
Uses file _✓n_✓a_✓m_✓e as standard output like `>' but places output at the
end of the file. If the variable _✓n_✓o_✓c_✓l_✓o_✓b_✓b_✓e_✓r is set, then it is an
error for the file not to exist unless one of the `!' forms is
given. Otherwise similar to `>'.
A command receives the environment in which the shell was invoked as
modified by the input-output parameters and the presence of the command
in a pipeline. Thus, unlike some previous shells, commands run from a
file of shell commands have no access to the text of the commands by
default; rather they receive the original standard input of the shell.
The `<<' mechanism should be used to present inline data. This permits
shell command scripts to function as components of pipelines and allows
the shell to block read its input. Note that the default standard input
for a command run detached is not modified to be the empty file
`/dev/null'; rather the standard input remains as the original standard
input of the shell. If this is a terminal and if the process attempts
to read from the terminal, then the process will block and the user will
be notified (see Jobs above.)
Diagnostic output may be directed through a pipe with the standard out-
put. Simply use the form `|&' rather than just `|'.
Expressions
A number of the built-in commands (to be described subsequently) take
expressions, in which the operators are similar to those of C, with the
same precedence. These expressions appear in the @, _✓e_✓x_✓i_✓t, _✓i_✓f, and _✓w_✓h_✓i_✓l_✓e
commands. The following operators are available:
|| && | ! & == != =~ !~ <= >= < > << >> + - * /
% ! ~ ( )
Here the precedence increases to the right, `==' `!=' `=~' and `!~',
`<=' `>=' `<' and `>', `<<' and `>>', `+' and `-', `*' `/' and `%'
being, in groups, at the same level. The `==' `!=' `=~' and `!~' opera-
tors compare their arguments as strings; all others operate on numbers.
The operators `=~' and `!~' are like `!=' and `==' except that the right
hand side is a _✓p_✓a_✓t_✓t_✓e_✓r_✓n (containing, for example, `*'s, `?'s and
instances of `[...]') against which the left hand operand is matched.
This reduces the need for use of the _✓s_✓w_✓i_✓t_✓c_✓h statement in shell scripts
when all that is really needed is pattern matching.
Strings which begin with `0' are considered octal numbers. Null or
missing arguments are considered `0'. The result of all expressions are
strings, which represent decimal numbers. It is important to note that
no two components of an expression can appear in the same word; except
when adjacent to components of expressions which are syntactically sig-
nificant to the parser (`&' `|' `<' `>' `(' `)') they should be sur-
rounded by spaces.
Also available in expressions as primitive operands are command execu-
tions enclosed in `{' and `}' and file enquiries of the form `-_✓l name'
where _✓l is one of:
r read access
w write access
x execute access
e existence
o ownership
z zero size
f plain file
d directory
The specified name is command and file name expanded and then tested to
see if it has the specified relationship to the real user. If the file
does not exist or is inaccessible then all enquiries return false, that
is `0'. Command executions succeed, returning true, that is `1', if the
command exits with status 0, otherwise they fail, returning false, that
is `0'. If more detailed status information is required then the com-
mand should be executed outside of an expression and the variable _✓s_✓t_✓a_✓t_✓u_✓s
examined.
Control Flow
The shell contains a number of commands which can be used to regulate
the flow of control in command files (shell scripts) and (in limited but
useful ways) from terminal input. These commands all operate by forcing
the shell to reread or skip in its input and, due to the implementation,
restrict the placement of some of the commands.
The _✓f_✓o_✓r_✓e_✓a_✓c_✓h, _✓s_✓w_✓i_✓t_✓c_✓h, and _✓w_✓h_✓i_✓l_✓e statements, as well as the _✓i_✓f-_✓t_✓h_✓e_✓n-_✓e_✓l_✓s_✓e
form of the _✓i_✓f statement require that the major keywords appear in a
single simple command on an input line as shown below.
If the shell's input is not seekable, the shell buffers up input when-
ever a loop is being read and performs seeks in this internal buffer to
accomplish the rereading implied by the loop. (To the extent that this
allows, backward goto's will succeed on non-seekable inputs.)
Built-in Commands
Built-in commands are executed within the shell. If a built-in command
occurs as any component of a pipeline except the last then it is exe-
cuted in a subshell.
alias
alias name
alias name wordlist
The first form prints all aliases. The second form prints the
alias for name. The final form assigns the specified _✓w_✓o_✓r_✓d_✓l_✓i_✓s_✓t as
the alias of _✓n_✓a_✓m_✓e; _✓w_✓o_✓r_✓d_✓l_✓i_✓s_✓t is command and file name substituted.
_✓N_✓a_✓m_✓e is not allowed to be _✓a_✓l_✓i_✓a_✓s or _✓u_✓n_✓a_✓l_✓i_✓a_✓s.
alloc
Shows the amount of dynamic core in use, broken down into used and
free core, and address of the last location in the heap. With an
argument shows each used and free block on the internal dynamic
memory chain indicating its address, size, and whether it is used
or free. This is a debugging command and may not work in produc-
tion versions of the shell; it requires a modified version of the
system memory allocator.
bg
bg %job ...
Puts the current or specified jobs into the background, continuing
them if they were stopped.
break
Causes execution to resume after the _✓e_✓n_✓d of the nearest enclosing
_✓f_✓o_✓r_✓e_✓a_✓c_✓h or _✓w_✓h_✓i_✓l_✓e. The remaining commands on the current line are
executed. Multi-level breaks are thus possible by writing them all
on one line.
breaksw
Causes a break from a _✓s_✓w_✓i_✓t_✓c_✓h, resuming after the _✓e_✓n_✓d_✓s_✓w.
case label:
A label in a _✓s_✓w_✓i_✓t_✓c_✓h statement as discussed below.
cd
cd name
chdir
chdir name
Change the shell's working directory to directory _✓n_✓a_✓m_✓e. If no argu-
ment is given then change to the home directory of the user.
If _✓n_✓a_✓m_✓e is not found as a subdirectory of the current directory
(and does not begin with `/', `./' or `../'), then each component
of the variable _✓c_✓d_✓p_✓a_✓t_✓h is checked to see if it has a subdirectory
_✓n_✓a_✓m_✓e. Finally, if all else fails but _✓n_✓a_✓m_✓e is a shell variable whose
value begins with `/', then this is tried to see if it is a direc-
tory.
continue
Continue execution of the nearest enclosing _✓w_✓h_✓i_✓l_✓e or _✓f_✓o_✓r_✓e_✓a_✓c_✓h. The
rest of the commands on the current line are executed.
default:
Labels the default case in a _✓s_✓w_✓i_✓t_✓c_✓h statement. The default should
come after all _✓c_✓a_✓s_✓e labels.
dirs
Prints the directory stack; the top of the stack is at the left,
the first directory in the stack being the current directory.
echo wordlist
echo -n wordlist
The specified words are written to the shell's standard output,
separated by spaces, and terminated with a new line unless the -n
option is specified.
else
end
endif
endsw
See the description of the _✓f_✓o_✓r_✓e_✓a_✓c_✓h, _✓i_✓f, _✓s_✓w_✓i_✓t_✓c_✓h, and _✓w_✓h_✓i_✓l_✓e state-
ments below.
eval arg ...
As in sh(1). The arguments are read as input to the shell and the
resulting command(s) executed in the context of the current shell.
This is usually used to execute commands generated as the result of
command or variable substitution, since parsing occurs before these
substitutions. See _✓t_✓e_✓s_✓t(1) for an example of using _✓e_✓v_✓a_✓l.
exec command
The specified command is executed in place of the current shell.
exit
exit(expr)
The shell exits either with the value of the _✓s_✓t_✓a_✓t_✓u_✓s variable (first
form) or with the value of the specified _✓e_✓x_✓p_✓r (second form).
fg
fg %job ...
Brings the current or specified jobs into the foreground, continu-
ing them if they were stopped.
foreach name (wordlist)
...
end
The variable _✓n_✓a_✓m_✓e is successively set to each member of _✓w_✓o_✓r_✓d_✓l_✓i_✓s_✓t
and the sequence of commands between this command and the matching
_✓e_✓n_✓d are executed. (Both _✓f_✓o_✓r_✓e_✓a_✓c_✓h and _✓e_✓n_✓d must appear alone on
separate lines.)
The built-in command _✓c_✓o_✓n_✓t_✓i_✓n_✓u_✓e may be used to continue the loop
prematurely and the built-in command _✓b_✓r_✓e_✓a_✓k to terminate it prema-
turely. When this command is read from the terminal, the loop is
read up once prompting with `?' before any statements in the loop
are executed. If you make a mistake typing in a loop at the termi-
nal you can rub it out.
glob wordlist
Like _✓e_✓c_✓h_✓o but no `\' escapes are recognized and words are delimited
by null characters in the output. Useful for programs which wish
to use the shell to file name expand a list of words.
goto word
The specified _✓w_✓o_✓r_✓d is file name and command expanded to yield a
string of the form `label'. The shell rewinds its input as much as
possible and searches for a line of the form `label:' possibly pre-
ceded by blanks or tabs. Execution continues after the specified
line.
hashstat
Print a statistics line indicating how effective the internal hash
table has been at locating commands (and avoiding _✓e_✓x_✓e_✓c's). An _✓e_✓x_✓e_✓c
is attempted for each component of the _✓p_✓a_✓t_✓h where the hash function
indicates a possible hit, and in each component which does not
begin with a `/'.
history
history _✓n
history -r _✓n
history -h _✓n
Displays the history event list; if _✓n is given only the _✓n most
recent events are printed. The -r option reverses the order of
printout to be most recent first rather than oldest first. The -h
option causes the history list to be printed without leading
numbers. This is used to produce files suitable for sourcing using
the -h option to _✓s_✓o_✓u_✓r_✓c_✓e.
if (expr) command
If the specified expression evaluates true, then the single _✓c_✓o_✓m_✓m_✓a_✓n_✓d
with arguments is executed. Variable substitution on _✓c_✓o_✓m_✓m_✓a_✓n_✓d hap-
pens early, at the same time it does for the rest of the _✓i_✓f com-
mand. _✓C_✓o_✓m_✓m_✓a_✓n_✓d must be a simple command, not a pipeline, a command
list, or a parenthesized command list. Input/output redirection
occurs even if _✓e_✓x_✓p_✓r is false, when command is not executed (this is
a bug).
if (expr) then
...
else if (expr2) then
...
else
...
endif
If the specified _✓e_✓x_✓p_✓r is true then the commands to the first _✓e_✓l_✓s_✓e
are executed; else if _✓e_✓x_✓p_✓r_✓2 is true then the commands to the second
else are executed, etc. Any number of _✓e_✓l_✓s_✓e-_✓i_✓f pairs are possible;
only one _✓e_✓n_✓d_✓i_✓f is needed. The _✓e_✓l_✓s_✓e part is likewise optional.
(The words _✓e_✓l_✓s_✓e and _✓e_✓n_✓d_✓i_✓f must appear at the beginning of input
lines; the _✓i_✓f must appear alone on its input line or after an
_✓e_✓l_✓s_✓e.)
jobs
jobs -l
Lists the active jobs; given the -l options lists process id's in
addition to the normal information.
kill %job
kill -sig %job ...
kill pid
kill -sig pid ...
kill -l
Sends either the TERM (terminate) signal or the specified signal to
the specified jobs or processes. Signals are either given by
number or by names (as given in /_✓u_✓s_✓r/_✓i_✓n_✓c_✓l_✓u_✓d_✓e/_✓s_✓i_✓g_✓n_✓a_✓l._✓h, stripped of
the prefix ``SIG''). The signal names are listed by ``kill -l''.
There is no default, saying just `kill' does not send a signal to
the current job. If the signal being sent is TERM (terminate) or
HUP (hangup), then the job or process will be sent a CONT (con-
tinue) signal as well.
limit
limit _✓r_✓e_✓s_✓o_✓u_✓r_✓c_✓e
limit _✓r_✓e_✓s_✓o_✓u_✓r_✓c_✓e _✓m_✓a_✓x_✓i_✓m_✓u_✓m-_✓u_✓s_✓e
Limits the consumption by the current process and each process it
creates to not individually exceed _✓m_✓a_✓x_✓i_✓m_✓u_✓m-_✓u_✓s_✓e on the specified
_✓r_✓e_✓s_✓o_✓u_✓r_✓c_✓e. If no _✓m_✓a_✓x_✓i_✓m_✓u_✓m-_✓u_✓s_✓e is given, then the current limit is
printed; if no _✓r_✓e_✓s_✓o_✓u_✓r_✓c_✓e is given, then all limitations are given.
The following resources can be controlled:
o✓+ _✓c_✓p_✓u_✓t_✓i_✓m_✓e (maximum number of cpu-seconds to be used by each process)
o✓+ _✓f_✓i_✓l_✓e_✓s_✓i_✓z_✓e (largest single file which can be created)
o✓+ _✓d_✓a_✓t_✓a_✓s_✓i_✓z_✓e (the maximum growth of the data+stack region by _✓s_✓b_✓r_✓k(2)
beyond the end of the program text)
o✓+ _✓s_✓t_✓a_✓c_✓k_✓s_✓i_✓z_✓e (the maximum size of the automatically-extended stack
region)
o✓+ _✓c_✓o_✓r_✓e_✓d_✓u_✓m_✓p_✓s_✓i_✓z_✓e (the size of the largest core dump that can be
created).
o✓+ _✓m_✓e_✓m_✓o_✓r_✓y_✓u_✓s_✓e (the maximum amount of main memory a process is allowed
to occupy)
The _✓m_✓a_✓x_✓i_✓m_✓u_✓m-_✓u_✓s_✓e may be given as a (floating point or integer)
number followed by a scale factor. For all limits other than _✓c_✓p_✓u_✓-
_✓t_✓i_✓m_✓e the default scale is `k' or `kilobytes' (1024 bytes); a scale
factor of `m' or `megabytes' may also be used. For _✓c_✓p_✓u_✓t_✓i_✓m_✓e the
default scaling is `seconds', while `m' for minutes or `h' for
hours, or a time of the form `mm:ss' giving minutes and seconds may
be used.
For both _✓r_✓e_✓s_✓o_✓u_✓r_✓c_✓e names and scale factors, unambiguous prefixes of
the names suffice.
login
Terminate a login shell, replacing it with an instance of
/bin/login. This is one way to log off, included for compatibility
with _✓s_✓h(1).
logout
Terminate a login shell. Especially useful if _✓i_✓g_✓n_✓o_✓r_✓e_✓e_✓o_✓f is set.
nice
nice +number
nice command
nice +number command
The first form sets the _✓n_✓i_✓c_✓e for this shell to 4. The second form
sets the _✓n_✓i_✓c_✓e to the given number. The final two forms run command
at priority 4 and _✓n_✓u_✓m_✓b_✓e_✓r respectively. The super-user may specify
negative niceness by using `nice -number ...'. Command is always
executed in a sub-shell, and the restrictions place on commands in
simple _✓i_✓f statements apply.
nohup
nohup command
The first form can be used in shell scripts to cause hangups to be
ignored for the remainder of the script. The second form causes
the specified command to be run with hangups ignored. All
processes detached with `&' are effectively _✓n_✓o_✓h_✓u_✓p'_✓e_✓d.
notify
notify %job ...
Causes the shell to notify the user asynchronously when the status
of the current or specified jobs changes; normally notification is
presented before a prompt. This is automatic if the shell variable
_✓n_✓o_✓t_✓i_✓f_✓y is set.
onintr
onintr -
onintr label
Control the action of the shell on interrupts. The first form
restores the default action of the shell on interrupts which is to
terminate shell scripts or to return to the terminal command input
level. The second form `onintr -' causes all interrupts to be
ignored. The final form causes the shell to execute a `goto label'
when an interrupt is received or a child process terminates because
it was interrupted.
In any case, if the shell is running detached and interrupts are
being ignored, all forms of _✓o_✓n_✓i_✓n_✓t_✓r have no meaning and interrupts
continue to be ignored by the shell and all invoked commands.
popd
popd +n
Pops the directory stack, returning to the new top directory. With
a argument `+_✓n' discards the _✓nth entry in the stack. The elements
of the directory stack are numbered from 0 starting at the top.
pushd
pushd name
pushd +n
With no arguments, pushd exchanges the top two elements of the
directory stack. Given a _✓n_✓a_✓m_✓e argument, pushd changes to the new
directory (using _✓c_✓d) and pushes the old current working directory
(as in _✓c_✓s_✓w) onto the directory stack. With a numeric argument,
rotates the _✓nth argument of the directory stack around to be the
top element and changes to it. The members of the directory stack
are numbered from the top starting at 0.
rehash
Causes the internal hash table of the contents of the directories
in the _✓p_✓a_✓t_✓h variable to be recomputed. This is needed if new com-
mands are added to directories in the _✓p_✓a_✓t_✓h while you are logged in.
This should only be necessary if you add commands to one of your
own directories, or if a systems programmer changes the contents of
one of the system directories.
repeat count command
The specified _✓c_✓o_✓m_✓m_✓a_✓n_✓d which is subject to the same restrictions as
the _✓c_✓o_✓m_✓m_✓a_✓n_✓d in the one line _✓i_✓f statement above, is executed _✓c_✓o_✓u_✓n_✓t
times. I/O redirections occur exactly once, even if _✓c_✓o_✓u_✓n_✓t is 0.
set
set name
set name=word
set name[index]=word
set name=(wordlist)
The first form of the command shows the value of all shell vari-
ables. Variables which have other than a single word as value
print as a parenthesized word list. The second form sets _✓n_✓a_✓m_✓e to
the null string. The third form sets _✓n_✓a_✓m_✓e to the single _✓w_✓o_✓r_✓d. The
fourth form sets the _✓i_✓n_✓d_✓e_✓x'_✓t_✓h component of name to word; this com-
ponent must already exist. The final form sets _✓n_✓a_✓m_✓e to the list of
words in _✓w_✓o_✓r_✓d_✓l_✓i_✓s_✓t. In all cases the value is command and file name
expanded.
These arguments may be repeated to set multiple values in a single
set command. Note however, that variable expansion happens for all
arguments before any setting occurs.
setenv name value
Sets the value of environment variable _✓n_✓a_✓m_✓e to be _✓v_✓a_✓l_✓u_✓e, a single
string. The most commonly used environment variable USER, TERM,
and PATH are automatically imported to and exported from the _✓c_✓s_✓h
variables _✓u_✓s_✓e_✓r, _✓t_✓e_✓r_✓m, and _✓p_✓a_✓t_✓h; there is no need to use _✓s_✓e_✓t_✓e_✓n_✓v for
these.
shift
shift variable
The members of _✓a_✓r_✓g_✓v are shifted to the left, discarding _✓a_✓r_✓g_✓v[_✓1]. It
is an error for _✓a_✓r_✓g_✓v not to be set or to have less than one word as
value. The second form performs the same function on the specified
variable.
source name
source -h name
The shell reads commands from _✓n_✓a_✓m_✓e. _✓S_✓o_✓u_✓r_✓c_✓e commands may be nested;
if they are nested too deeply the shell may run out of file
descriptors. An error in a _✓s_✓o_✓u_✓r_✓c_✓e at any level terminates all
nested _✓s_✓o_✓u_✓r_✓c_✓e commands. Normally input during _✓s_✓o_✓u_✓r_✓c_✓e commands is
not placed on the history list; the -h option causes the commands
to be placed in the history list without being executed.
stop
stop %job ...
Stops the current or specified job which is executing in the back-
ground.
suspend
Causes the shell to stop in its tracks, much as if it had been sent
a stop signal with ^Z. This is most often used to stop shells
started by _✓s_✓u(1).
switch (string)
case str1:
...
breaksw
...
default:
...
breaksw
endsw
Each case label is successively matched, against the specified
_✓s_✓t_✓r_✓i_✓n_✓g which is first command and file name expanded. The file
metacharacters `*', `?' and `[...]' may be used in the case labels,
which are variable expanded. If none of the labels match before a
`default' label is found, then the execution begins after the
default label. Each case label and the default label must appear
at the beginning of a line. The command _✓b_✓r_✓e_✓a_✓k_✓s_✓w causes execution
to continue after the _✓e_✓n_✓d_✓s_✓w. Otherwise control may fall through
case labels and default labels as in C. If no label matches and
there is no default, execution continues after the _✓e_✓n_✓d_✓s_✓w.
time
time command
With no argument, a summary of time used by this shell and its
children is printed. If arguments are given the specified simple
command is timed and a time summary as described under the _✓t_✓i_✓m_✓e
variable is printed. If necessary, an extra shell is created to
print the time statistic when the command completes.
umask
umask value
The file creation mask is displayed (first form) or set to the
specified value (second form). The mask is given in octal. Common
values for the mask are 002 giving all access to the group and read
and execute access to others or 022 giving all access except no
write access for users in the group or others.
unalias pattern
All aliases whose names match the specified pattern are discarded.
Thus all aliases are removed by `unalias *'. It is not an error
for nothing to be _✓u_✓n_✓a_✓l_✓i_✓a_✓s_✓e_✓d.
unhash
Use of the internal hash table to speed location of executed pro-
grams is disabled.
unlimit _✓r_✓e_✓s_✓o_✓u_✓r_✓c_✓e
unlimit
Removes the limitation on _✓r_✓e_✓s_✓o_✓u_✓r_✓c_✓e. If no _✓r_✓e_✓s_✓o_✓u_✓r_✓c_✓e is specified,
then all _✓r_✓e_✓s_✓o_✓u_✓r_✓c_✓e limitations are removed.
unset pattern
All variables whose names match the specified pattern are removed.
Thus all variables are removed by `unset *'; this has noticeably
distasteful side-effects. It is not an error for nothing to be
_✓u_✓n_✓s_✓e_✓t.
unsetenv pattern
Removes all variables whose name match the specified pattern from
the environment. See also the _✓s_✓e_✓t_✓e_✓n_✓v command above and _✓p_✓r_✓i_✓n_✓-
_✓t_✓e_✓n_✓v(1).
wait
All background jobs are waited for. It the shell is interactive,
then an interrupt can disrupt the wait, at which time the shell
prints names and job numbers of all jobs known to be outstanding.
while (expr)
...
end
While the specified expression evaluates non-zero, the commands
between the _✓w_✓h_✓i_✓l_✓e and the matching end are evaluated. _✓B_✓r_✓e_✓a_✓k and
_✓c_✓o_✓n_✓t_✓i_✓n_✓u_✓e may be used to terminate or continue the loop prematurely.
(The _✓w_✓h_✓i_✓l_✓e and _✓e_✓n_✓d must appear alone on their input lines.) Prompt-
ing occurs here the first time through the loop as for the _✓f_✓o_✓r_✓e_✓a_✓c_✓h
statement if the input is a terminal.
%job
Brings the specified job into the foreground.
%job &
Continues the specified job in the background.
@
@ name = expr
@ name[index] = expr
The first form prints the values of all the shell variables. The
second form sets the specified _✓n_✓a_✓m_✓e to the value of _✓e_✓x_✓p_✓r. If the
expression contains `<', `>', `&' or `|' then at least this part of
the expression must be placed within `(' `)'. The third form
assigns the value of _✓e_✓x_✓p_✓r to the _✓i_✓n_✓d_✓e_✓x'_✓t_✓h argument of _✓n_✓a_✓m_✓e. Both
_✓n_✓a_✓m_✓e and its _✓i_✓n_✓d_✓e_✓x'_✓t_✓h component must already exist.
The operators `*=', `+=', etc are available as in C. The space
separating the name from the assignment operator is optional.
Spaces are, however, mandatory in separating components of _✓e_✓x_✓p_✓r
which would otherwise be single words.
Special postfix `++' and `--' operators increment and decrement
_✓n_✓a_✓m_✓e respectively, that is `@ i++'.
Pre-defined And Environment Variables
The following variables have special meaning to the shell. Of these,
_✓a_✓r_✓g_✓v, _✓c_✓w_✓d, _✓h_✓o_✓m_✓e, _✓p_✓a_✓t_✓h, _✓p_✓r_✓o_✓m_✓p_✓t, _✓s_✓h_✓e_✓l_✓l and _✓s_✓t_✓a_✓t_✓u_✓s are always set by the
shell. Except for _✓c_✓w_✓d and _✓s_✓t_✓a_✓t_✓u_✓s this setting occurs only at initiali-
zation; these variables will not then be modified unless this is done
explicitly by the user.
This shell copies the environment variable USER into the variable _✓u_✓s_✓e_✓r,
TERM into _✓t_✓e_✓r_✓m, and HOME into _✓h_✓o_✓m_✓e, and copies these back into the
environment whenever the normal shell variables are reset. The environ-
ment variable PATH is likewise handled. It is not necessary to worry
about its setting other than in the file ._✓c_✓s_✓h_✓r_✓c as inferior _✓c_✓s_✓h
processes will import the definition of _✓p_✓a_✓t_✓h from the environment, and
re-export it if you then change it.
argv Set to the arguments to the shell, it is from this vari-
able that positional parameters are substituted, that is
`$1' is replaced by `$argv[1]', and so forth.
cdpath Gives a list of alternate directories searched to find
subdirectories in _✓c_✓h_✓d_✓i_✓r commands.
cwd The full pathname of the current directory.
echo Set when the -x command line option is given. Causes
each command and its arguments to be echoed just before
it is executed. For non-built-in commands all expansions
occur before echoing. Built-in commands are echoed
before command and file name substitution, since these
substitutions are then done selectively.
histchars Can be given a string value to change the characters used
in history substitution. The first character of its
value is used as the history substitution character,
replacing the default character !. The second character
of its value replaces the character ! in quick substitu-
tions.
history Can be given a numeric value to control the size of the
history list. Any command which has been referenced in
this many events will not be discarded. Too large values
of _✓h_✓i_✓s_✓t_✓o_✓r_✓y may run the shell out of memory. The last
executed command is always saved on the history list.
home The home directory of the invoker, initialized from the
environment. The file name expansion of `~' refers to
this variable.
ignoreeof If set the shell ignores end-of-file from input devices
which are terminals. This prevents shells from acciden-
tally being killed by control-D's.
mail The files where the shell checks for mail. This is done
after each command completion which will result in a
prompt, if a specified interval has elapsed. The shell
says `You have new mail.' if the file exists with an
access time not greater than its modify time.
If the first word of the value of _✓m_✓a_✓i_✓l is numeric it
specifies a different mail checking interval, in seconds,
than the default, which is 10 minutes.
If multiple mail files are specified, then the shell says
`New mail in _✓n_✓a_✓m_✓e' when there is mail in the file _✓n_✓a_✓m_✓e.
noclobber As described in the section on _✓I_✓n_✓p_✓u_✓t/_✓o_✓u_✓t_✓p_✓u_✓t, restrictions
are placed on output redirection to insure that files are
not accidentally destroyed, and that `>>' redirections
refer to existing files.
noglob If set, file name expansion is inhibited. This is most
useful in shell scripts which are not dealing with file
names, or after a list of file names has been obtained
and further expansions are not desirable.
nonomatch If set, it is not an error for a file name expansion to
not match any existing files; rather the primitive pat-
tern is returned. It is still an error for the primitive
pattern to be malformed, that is `echo [' still gives an
error.
notify If set, the shell notifies asynchronously of job comple-
tions. The default is to rather present job completions
just before printing a prompt.
path Each word of the path variable specifies a directory in
which commands are to be sought for execution. A null
word specifies the current directory. If there is no
_✓p_✓a_✓t_✓h variable then only full path names will execute.
The usual search path is `.', `/bin' and `/usr/bin', but
this may vary from system to system. For the super-user
the default search path is `/etc', `/bin' and `/usr/bin'.
A shell which is given neither the -c nor the -t option
will normally hash the contents of the directories in the
_✓p_✓a_✓t_✓h variable after reading ._✓c_✓s_✓h_✓r_✓c, and each time the
_✓p_✓a_✓t_✓h variable is reset. If new commands are added to
these directories while the shell is active, it may be
necessary to give the _✓r_✓e_✓h_✓a_✓s_✓h or the commands may not be
found.
prompt The string which is printed before each command is read
from an interactive terminal input. If a `!' appears in
the string it will be replaced by the current event
number unless a preceding `\' is given. Default is `% ',
or `# ' for the super-user.
savehist is given a numeric value to control the number of entries
of the history list that are saved in ~/.history when the
user logs out. Any command which has been referenced in
this many events will be saved. During start up the
shell sources ~/.history into the history list enabling
history to be saved across logins. Too large values of
_✓s_✓a_✓v_✓e_✓h_✓i_✓s_✓t will slow down the shell during start up.
shell The file in which the shell resides. This is used in
forking shells to interpret files which have execute bits
set, but which are not executable by the system. (See
the description of _✓N_✓o_✓n-_✓b_✓u_✓i_✓l_✓t-_✓i_✓n _✓C_✓o_✓m_✓m_✓a_✓n_✓d _✓E_✓x_✓e_✓c_✓u_✓t_✓i_✓o_✓n below.)
Initialized to the (system-dependent) home of the shell.
status The status returned by the last command. If it ter-
minated abnormally, then 0200 is added to the status.
Built-in commands which fail return exit status `1', all
other built-in commands set status `0'.
time Controls automatic timing of commands. If set, then any
command which takes more than this many cpu seconds will
cause a line giving user, system, and real times and a
utilization percentage which is the ratio of user plus
system times to real time to be printed when it ter-
minates. The time command can be used to cause a command
to be timed no matter how much CPU time it takes. Thus
% time cp /etc/rc /usr/bill/rc
0.0u 0.1s 0:01 8% 2+1k 3+2io 1pf+0w
% time wc /etc/rc /usr/bill/rc
52 178 1347 /etc/rc
52 178 1347 /usr/bill/rc
104 356 2694 total
0.1u 0.1s 0:00 13% 3+3k 5+3io 7pf+0w
%
The preceding example indicates that the _✓c_✓p command used
a negligible amount of user time (u) and about 1/10th of
a second system time (s); the elapsed time was 1 second
(0:01), there was an average memory usage of 2k bytes of
program space and 1k bytes of data space over the cpu
time involved (2+1k); the program did three disk reads
and two disk writes (3+2io), and took one page fault and
was not swapped (1pf+0w). The word count command _✓w_✓c on
the other hand used 0.1 seconds of user time and 0.1
seconds of system time in less than a second of elapsed
time. The percentage `13%' indicates that over the
period when it was active the command `wc' used an aver-
age of 13 percent of the available CPU cycles of the
machine.
verbose Set by the -v command line option, causes the words of
each command to be printed after history substitution.
Non-built-in Command Execution
When a command to be executed is found to not be a built-in command the
shell attempts to execute the command via _✓e_✓x_✓e_✓c_✓v_✓e(2). Each word in the
variable _✓p_✓a_✓t_✓h names a directory from which the shell will attempt to
execute the command. If it is given neither a -c nor a -t option, the
shell will hash the names in these directories into an internal table so
that it will only try an _✓e_✓x_✓e_✓c in a directory if there is a possibility
that the command resides there. This greatly speeds command location
when a large number of directories are present in the search path. If
this mechanism has been turned off (via _✓u_✓n_✓h_✓a_✓s_✓h), or if the shell was
given a -c or -t argument, and in any case for each directory component
of _✓p_✓a_✓t_✓h which does not begin with a `/', the shell concatenates with the
given command name to form a path name of a file which it then attempts
to execute.
Parenthesized commands are always executed in a subshell. Thus `(cd ;
pwd) ; pwd' prints the _✓h_✓o_✓m_✓e directory; leaving you where you were
(printing this after the home directory), while `cd ; pwd' leaves you in
the _✓h_✓o_✓m_✓e directory. Parenthesized commands are most often used to
prevent _✓c_✓h_✓d_✓i_✓r from affecting the current shell.
If the file has execute permissions but is not an executable binary to
the system, then it is assumed to be a file containing shell commands
and a new shell is spawned to read it.
If there is an _✓a_✓l_✓i_✓a_✓s for _✓s_✓h_✓e_✓l_✓l then the words of the alias will be
prepended to the argument list to form the shell command. The first
word of the _✓a_✓l_✓i_✓a_✓s should be the full path name of the shell (for exam-
ple, `$shell'). Note that this is a special, late occurring, case of
_✓a_✓l_✓i_✓a_✓s substitution, and only allows words to be prepended to the argu-
ment list without modification.
Argument List Processing
If argument 0 to the shell is `-' then this is a login shell. The flag
arguments are interpreted as follows:
-c The first argument word is taken to be a command string. All
remaining argument words are placed in _✓a_✓r_✓g_✓v.
-e The shell exits if any invoked command terminates abnormally or
yields a non-zero exit status.
-f The shell will start faster, because it will neither search for nor
execute commands from the file `.cshrc' in the invokers home
directory.
-i The shell is interactive and prompts for its top-level input, even
if stdin appears not to be a terminal. Shells are interactive
without this option if their inputs and outputs are terminals.
-n Commands are parsed, but not executed. This aids in syntactic
checking of shell scripts.
-s Command input is taken from the standard input.
-t A single line of input is read and executed. A `\' may be used to
escape the new line at the end of this line and continue onto
another line.
-v Causes the _✓v_✓e_✓r_✓b_✓o_✓s_✓e variable to be set, with the effect that command
input is echoed after history substitution.
-x Causes the _✓e_✓c_✓h_✓o variable to be set, so that commands are echoed
immediately before execution.
-V Causes the _✓v_✓e_✓r_✓b_✓o_✓s_✓e variable to be set even before `.cshrc' is exe-
cuted.
-X Causes the echo variable to be set before `.cshrc' is executed.
After processing of flag arguments if arguments remain but none of the
-c, -i, -s, or -t options was given the first argument is taken as the
name of a file of commands to be executed. The shell opens this file,
and saves its name for possible resubstitution by `$0'. Since many sys-
tems use either the standard version 6 or version 7 shells whose shell
scripts are not compatible with this shell, the shell will execute such
a `standard' shell if the first character of a script is not a `#', that
is if the script does not start with a comment. Remaining arguments
initialize the variable _✓a_✓r_✓g_✓v.
Signal Handling
The shell normally ignores _✓q_✓u_✓i_✓t signals. Jobs running detached (either
by `&' or the _✓b_✓g or %... & commands) are immune to signals generated
from the keyboard, including hangups. Other signals have the values
which the shell inherited from its parent. The shells handling of
interrupts and terminate signals in shell scripts can be controlled by
_✓o_✓n_✓i_✓n_✓t_✓r. Login shells catch the _✓t_✓e_✓r_✓m_✓i_✓n_✓a_✓t_✓e signal; otherwise this signal
is passed on to children from the state in the shell's parent. In no
case are interrupts allowed when a login shell is reading the file
`.logout'.
Command And Filename Recognition
The _✓c_✓s_✓h command recognizes and completes user name aliases, commands
(including built-in _✓c_✓s_✓h commands), and filenames. To use this feature,
do the following:
1. Type enough characters at the prompt to make your input to the system
unique.
2. Press the ESC key.
If your input is unique, the Shell completes the input line. If the
input is not unique, the terminal signals you with a beep. If you
receive a beep, type CTRL/D for a list of options. You can then type
the additional characters that will make your text unique. After you
have provided more input, press the ESC key again.
Restrictions
Words can be no longer than 1024 characters.
The system limits argument lists to 10240 characters.
The number of arguments to a command which involves file name expansion
is limited to 1/6'th the number of characters allowed in an argument
list.
Command substitutions may substitute no more characters than are allowed
in an argument list.
To detect looping, the shell restricts the number of _✓a_✓l_✓i_✓a_✓s substitutions
on a single line to 20.
When a command is restarted from a stop, the shell prints the directory
it started in if this is different from the current directory; this can
be misleading (that is, wrong) as the job may have changed directories
internally.
Shell built-in functions are not stoppable/restartable. Command
sequences of the form `a ; b ; c' are also not handled gracefully when
stopping is attempted. If you suspend `b', the shell will then immedi-
ately execute `c'. This is especially noticeable if this expansion
results from an _✓a_✓l_✓i_✓a_✓s. It suffices to place the sequence of commands in
()'s to force it to a subshell, that is `( a ; b ; c )'.
Commands within loops, prompted for by `?', are not placed in the _✓h_✓i_✓s_✓-
_✓t_✓o_✓r_✓y list. Control structure should be parsed rather than being recog-
nized as built-in commands. This would allow control commands to be
placed anywhere, to be combined with `|', and to be used with `&' and
`;' metasyntax.
It should be possible to use the colon (:) modifiers on the output of
command substitutions. All and more than one colon (:) modifier should
be allowed on `$' substitutions.
Symbolic links fool the shell. In particular, _✓d_✓i_✓r_✓s and `cd ..' don't
work properly once you've crossed through a symbolic link.
Files
~/.cshrc Read at beginning of execution by each shell.
~/.login Read by login shell, after `.cshrc' at login.
~/.logout Read by login shell, at logout.
/bin/sh Standard shell, for shell scripts not starting with a `#'.
/tmp/sh* Temporary file for `<<'.
/etc/passwd Source of home directories for `~name'.
See Also
sh(1), time(1), access(2), execve(2), fork(2), killpg(2), pipe(2),
sigvec(2), setrlimit(2), umask(2), wait(2), tty(4), a.out(5),
environ(7), time(7)
"An Introduction to the C shell", _✓S_✓u_✓p_✓p_✓l_✓e_✓m_✓e_✓n_✓t_✓a_✓r_✓y _✓D_✓o_✓c_✓u_✓m_✓e_✓n_✓t_✓s, _✓V_✓o_✓l_✓u_✓m_✓e _✓1:
_✓G_✓e_✓n_✓e_✓r_✓a_✓l _✓U_✓s_✓e_✓r